import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../../../providers/ApiPro.service';
import { ActivatedRoute , Router, RouterLink, RouterModule} from '@angular/router';
import { HybCheckMoney, HybSendOutGoodsInfoDto, HybTransportPic} from '../HuoCustmp.model';
import { NzModalService } from 'ng-zorro-antd';



@Component({
  selector: 'app-HuoCusWaybinfo',
  templateUrl: './HuoCusWaybinfo.component.html',
  styleUrls: ['./HuoCusWaybinfo.component.scss']
})
export class HuoCusWaybinfoComponent implements OnInit {
  public data: HybSendOutGoodsInfoDto = new HybSendOutGoodsInfoDto();
  public isoilCardPay: boolean;
  public isbankCardTransfer: boolean;
  public isCheck: boolean = false;
  public checkMoney: HybCheckMoney = new HybCheckMoney();
  public tranSportPic: HybTransportPic = new HybTransportPic();
  constructor(
    private apiService: ApiService,
    private route: ActivatedRoute,
    private confirmServ: NzModalService,
    private router: Router,
  ) { }

  ngOnInit() {
    this.getId();
  }

  getId(){
     this.route.params.subscribe((params) => {
          console.log(params['id']);
            this.load(params['id']);
             if(params['check'] == 'check' ){
              this.isCheck = true;
            }// 通过这个方法来判断是否为结算
        });
  }


  load(id){
    let url = "findtransportorderdetail"
    this.apiService.get(url,{"transportOrderId":id})
      .then(res =>{
        console.log(res);
        this.data = res.result;
        this.checkMoney.transportOrderId = this.data.transportOrderId;
      })
  }

  clearSend(){
    if(!this.isoilCardPay){
      this.checkMoney.oilCardPay = null;
    }
    if(!this.isbankCardTransfer){
      this.checkMoney.bankCardTransfer = null;
    }
  }

  save(){
    console.log(this.checkMoney);
    let url = "settleaccountstransportOrder";
    this.apiService.Postformdata(url,this.checkMoney)
      .then(res =>{
        if(res.result){
          this.success();
        }else{
          this.error(res.errMsg);
        }
      })
    .catch(err =>{
      this.errorInt();
    })
  }

  error(err) {
    this.confirmServ.error({
      title: '错误',
      content: err,
      okText:'返回'
    });
  }

  errorInt() {
    this.confirmServ.error({
      title: '错误404',
      content: '网络不稳定，请检查网络设备或与管理员联系',
      okText:'返回'
    });
  }

  success(){
    let self = this;
      this.confirmServ.success({
      title: '成功',
      content: '司机运费结算完成',
      okText:'完毕',
      onOk() {
          self.router.navigateByUrl("layout/cus/waybill");
      },

    });
  }

  info(contentTpl) {
    this.confirmServ.info({
      title: '这是一条通知信息',
      content: '<img src="'+contentTpl+'" alt="">'
    });
  }
  

}
